package com.huluobo.high3demo.home.items;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm.baen.BannerBeanResult;
import com.huluobo.mvvm.baen.GoodsBeanResult;
import com.huluobo.mvvm.model.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LC on 2023/9/18.
 */
public class ItemRepo extends BaseRepo {

    public void loadBanner(MutableLiveData<BannerBeanResult> bannerSuccess, MutableLiveData<String> bannerFailed) {
        apiService.getBanner().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BannerBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BannerBeanResult bannerBeanResult) {
                        bannerSuccess.setValue(bannerBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        bannerFailed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void loadGoods(int categoryId, int currentPage, int pageSze, MutableLiveData<GoodsBeanResult> goodsSuccess
            , MutableLiveData<String> goodsFailed) {
        apiService.getGoodsList(categoryId, currentPage, pageSze)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GoodsBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(GoodsBeanResult goodsBeanResult) {
                        goodsSuccess.setValue(goodsBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        goodsFailed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
